#include<string>
#include<vector>
using namespace std;
class Solution {
public:
    string compare(string& str1, string& str2) {
        int i = 0;
        string ret;
        while (i < str1.size() && i < str2.size()) {
            if (str1[i] == str2[i]) {
                ret.push_back(str1[i]);
            }
            else
                break;
            i++;
        }
        return ret;
    }
    string longestCommonPrefix(vector<string>& strs) {
        string ret = strs[0];
        for (int i = 1; i < strs.size(); i++) {
            ret = compare(ret, strs[i]);
        }
        return ret;
    }
};